<html>
<head>

<title>Groovy Goodness: Tell the Groovy Truth</title>

<script language="javascript" src="scripts/shCore.js"></script> 
<script language="javascript" src="scripts/shLegacy.js"></script> 
<script language="javascript" src="scripts/shBrushJava.js"></script> 
<script language="javascript" src="scripts/shBrushXml.js"></script> 
<script language="javascript" src="scripts/shBrushJScript.js"></script> 
<script language="javascript" src="scripts/shBrushGroovy.js"></script> 
<script language="javascript" src="scripts/shBrushPlain.js"></script> 
<script language="javascript" src="scripts/shBrushBash.js"></script> 
 
<link href="styles/reset.css" rel="stylesheet" type="text/css" />
<link href="styles/shCore.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="styles/shThemeRDark.css"/>
<link href="styles/blog.css" rel="stylesheet" type="text/css" />

</head>
<body>

<a href="index.html">Back to index</a>

<h3 class="post-title">Groovy Goodness: Tell the Groovy Truth</h3>

<div class="post">
<p>Groovy has a broader sence of what is true or false than the boolean expressions. For example an empty list or string is false in Groovy. This makes that we can write less code in conditional expressions to evaluate true or false:</p>
<pre class="brush:groovy">
// Booleans:
def b1 = false
def b2 = true
assert !b1
assert b2

// Strings:
def s1 = ''
def s2 = 'abc'
assert !s1
assert s2

// Numbers:
def n1 = 0
def n2 = 42
assert !n1
assert n2

// Lists, iterators:
def l1 = []
def l2 = [1, 3, 6]
assert !l1
assert l2
def i1 = l1.iterator()
def i2 = l2.iterator()
assert !i1
assert i2

// Maps:
def m1 = [:]
def m2 = ['key': 'value']
assert !m1
assert m2

// Objects:
def o1
def o2 = new Expando(name: 'groovy')
assert !o1
assert o2

// Matchers:
def ma1 = "groovy" =~ /java/
def ma2 = "groovy" =~ /groovy/
assert !ma1
assert ma2

</pre
</div>

<script language="javascript"> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
SyntaxHighlighter.defaults['first-line'] = 0;
SyntaxHighlighter.defaults['auto-links'] = false;
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>

</body>
</html>